package com.mygame;

import java.util.Random;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;

public class Sprite {
	
	private GameView gameView;
	private Bitmap bmp;
	private float x;
	private float y;
	private float width;
	private float height;
	private int Speed;
		
	
	public Sprite(GameView gameView, Bitmap bmp)
	{
		this.gameView = gameView;
		this.bmp = bmp;
		this.width = bmp.getWidth();
		this.height = bmp.getHeight();
		
		 Random rnd = new Random();
		 while (true) {
			 x = rnd.nextInt(Main.horSizeScreen-Main.horSizeScreen/10)+5;
			 if (Math.abs(x-Main.horSizeScreen/2)<rnd.nextDouble()*Main.horSizeScreen/2) 
			   	break;
			        
		 }
		 while (true ) {
			 y = rnd.nextInt(Main.widthTrack)+Main.vertSizeScreen/2-Main.widthTrack/2;
			 if (Math.abs(y-Main.vertSizeScreen/2)<rnd.nextDouble()*Main.widthTrack/2)
				 break;
		 }
		
		 if (Math.abs(x-Main.horSizeScreen/2)>Main.horSizeScreen/2.5
				 || Math.abs(y-Main.vertSizeScreen/2)>Main.widthTrack/2.5)
			   this.bmp = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.small);
		 else
			 if (Math.abs(x-Main.horSizeScreen/2)>Main.horSizeScreen/3
					 || Math.abs(y-Main.vertSizeScreen/2)>Main.widthTrack/3)
				 this.bmp = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.middle);
         Speed = 10;
	}
	
	public boolean isCollitionPipe(float x2, float y2)
    {
    	return x2 > x-5 && x2 < x + width+5 && y2 > y-5 && y2 < y + height+5;
		
    }
	
	public boolean isCollitionNose(float x2, float y2)
    {
    	
		return x2 > x-5 && x2 < x + width+5 && ( (y2+40 > y-5 && y2+40 < y + height+5) || (y2-40 > y-5 && y2-40 < y + height+5) );
		    
    }
		
	public void onDraw(Canvas canvas)
	{
		canvas.drawBitmap(bmp, x, y, null);
	}

	public float GetX()
	{
		return x;
	}
	
	public float GetY()
	{
		return y;
	}
	
	public void SetXY(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
	
	
	public float GetWidth()
	{
		return width;
	}
	
	public float GetHeight()
	{
		return height;
	}
}
